#ifndef __DOUBLELINKLIST_H_
#define __DOUBLELINKLIST_H_


#include <stddef.h>


using ElementType = int;

class DoubleLinkList
{
public:
    DoubleLinkList();
    void InsertTail(const ElementType& element);
    void InsertHead(const ElementType& element);
    void InsertByIndex(int index,const ElementType& element);

    void RemoveByIndex(int index);
    void RemoveByElement(const ElementType& element);

    void UpDateByElement(const ElementType &Oldelement,const ElementType &Newelement);

    ElementType& operator[](int index);

    size_t FindByElement(const ElementType& element);

    DoubleLinkList Merge(const DoubleLinkList & list);

    size_t Size();

    void Sort();
    void show();
    void ReserveShow(); //反向show

    bool isLoop();

    void MakeLoop();

private:
    struct Node
    {
        Node(const ElementType& element):value(element),next(nullptr),prev(nullptr){}
        ElementType value;
        Node *next;
        Node *prev;
    };
    void FastSort(Node *head,Node *tail);

    Node *head; //头指针
    Node *tail; //尾指针
    size_t size;
};


#endif